﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>流程查询</title>
    <link href="Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="Scripts/bootstrap/css/font-awesome.css" rel="stylesheet">
    <link href="Style/skin/css/style.css" rel="stylesheet" type="text/css" />
    <link href="Style/skin/css/animate.css" rel="stylesheet" type="text/css" />
    <link href="Comm/JS/layer/layer.css" rel="stylesheet" />
    <style>
        /*设置表格内容过长，用省略号代替多余部分，前提:table的style属性*/
        td {
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .pagination {
            margin: 8px 0;
            display: block;
            font-size: 13px;
        }

        .pagination .controls {
            float: left;
            border: 0;
            padding: 7px 0 0 15px;
            color: #777;
        }
    </style>
</head>

<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">

	<div class="ibox-content">
		<div class="row search-padding">
			<div class="col-md-8 col-sm-8">
				<div id="TSpan"></div>
			</div>
			<div class="col-md-4 col-sm-4 pull-right">
				<div class="form-inline">
					<div class="form-group">
						<input type='text' placeholder="请输入关键词" id='TB_Key' class="form-control" />
					</div>
					<button class="btn btn-success" type="button" onclick="javascript:SearchKey();"><i class="fa fa-search"></i> 查询</button>
				</div>
			</div>
		</div>	
		<div class="row search-padding">	
			<div class="col-md-12 col-sm-12">
				<div id="Flows"> </div>
			</div>
		</div>

		<table style="table-layout:fixed" class="table table-striped">
			<thead id="Table2">
			<tr >
				<th width='4%'>序号</th>
				<th width='23%'>标题</th>
				<th width='5%'>发起人</th>
				<th width='10%'>发起日期</th>
				<th width='15%'>停留节点</th>
				<th width='20%'>审批人</th>
				<th width='10%'>应完成日期</th>
				<th width='10%'>状态</th>
				<th width='5%'>操作</th>
			</tr>
			</thead>
			<tbody id="Table1"></tbody>
		</table>
         <!-- 显示分页信息 -->
        <div class="row" style="text-align: left;">
            <ul class="pagination" id="page_nav">
            </ul>
            <ul class="pagination controls" id="page_info">
            </ul>
            <div style="clear: both;"></div>
        </div>
	</div>
</div> 

<script type="text/javascript" src="Scripts/QueryString.js"></script>
    <script type="text/javascript" src="Scripts/QueryString.js"></script>
    <script type="text/javascript" src="Scripts/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="./Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="Scripts/bootstrap/bootstrap-paginator/js/bootstrap-paginator.js" type="text/javascript"></script>
    <!-- 导入配置文件. -->
    <script type="text/javascript" src="Scripts/config.js"></script>
    <script type="text/javascript" src="Comm/Gener.js"></script>
    <script src="Style/skin/layui/layer.js" type="text/javascript"></script>
    <script type="text/javascript">

        var webUser = null;
        var pageCount = 1; //页数
        var pageSize = 10; //一页显示行数
        var total = 0;
        var pageIdx = 1;//第几页
        var startIndex = 1;
        var realCount = 0;
        var flowData;
        var _tspan = GetQueryString("TSpan");
        var _flowNo = GetQueryString("FK_Flow");
        var pageInfo;
        var keyWord;
        var IsSearchClick = false;//是否点的查询 : fasle 不是 true 是
		var	 IsPageClick = false;//是否是点的页数 : false 不是 true 是
        $(function () {
            InitPage();//初始化查询列表、
            InitData();//初始化数据
            Paginator(pageCount, pageIdx); //分页
            mouseShow();//省略的展现出来
        });


        function InitPage(keyWord) {
            webUser = new WebUser();
            if (webUser.No == null)
                return;

            var url = "";
            if(IsSearchClick == true && IsPageClick == false){
                pageIdx = 1;

            }
            if (_tspan == undefined || _tspan == null || _tspan == "" || _tspan == "null") {
                _tspan = "-1";
            }

            
            if (_flowNo == undefined || _flowNo == null || _flowNo == "" || _flowNo == "null") {
                _flowNo = "";
            }

            if (_flowNo == "" && _tspan == "")
                _tspan = "-1";

            var handler = new HttpHandler("BP.WF.HttpHandler.WF");
            handler.AddPara("TSpan", _tspan);
            handler.AddPara("FK_Flow", _flowNo);
            handler.AddPara("KeyWord", keyWord);
            handler.AddPara("pageIdx", pageIdx);

            handler.AddPara("pageSize", pageSize);
            var data = handler.DoMethodReturnString("Search_Init");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            var data = JSON.parse(data);

            flowData = data['WF_GenerWorkFlow']; // 流程实例列表
            
            pageInfo = data['PageInfo'];//分页信息
            //时间段列表. 
            var tSpans = data['TSpan'];
            if (_tspan == "-1")
                html = "<button onclick=\"TSpan('');\" class=\"btn btn-info\" type=\"button\">全部</button> ";
            else
                html = "<button onclick=\"TSpan('');\" class=\"btn btn-default \" >全部</button> ";

            for (var i = 0; i < tSpans.length; i++) {

                var tSpan = tSpans[i];

                if (_tspan == tSpan.IntKey)
                    html += "<button onclick=\"TSpan('" + tSpan.IntKey + "');\" class=\"btn btn-info\" >" + tSpan.Lab + "</button> ";
                else
                    html += "<button onclick=\"TSpan('" + tSpan.IntKey + "');\" class=\"btn btn-default \">" + tSpan.Lab + "</button> ";
            }


            $("#TSpan").html(html);


            //流程名称列表.
            var flows = data['Flows'];
            if (_flowNo == null || _flowNo == "")
                html = "<button onclick=\"Flows('');\" class=\"btn btn-info\"  >全部</button> ";
            else
                html = "<button onclick=\"Flows('');\"  class=\"btn btn-default \" >全部</button> ";

            for (var i = 0; i < flows.length; i++) {
                var en = flows[i];

                if (_flowNo == en.No)
                    html += "<button onclick=\"Flows('" + en.No + "');\"  class=\"btn btn-info\"  >" + en.Name + "（" + en.Num + "）</button> ";
                else
                    html += "<button class=\"btn btn-default \"  onclick=\"Flows('" + en.No + "');\" >" + en.Name + "（" + en.Num + "）</button> ";
            }
            $("#Flows").html(html);

        }

        function InitData() {
            
            if (flowData.length <= 0) {
                alert('未查询出来数据');
                return;
            }
            //获取总条数，总页数，当前页第一条索引
            $.each(pageInfo, function(j,pi) {
                total = pi["totalNum"];
                pageCount = pi["totalPage"];
                startIndex = pi["startIndex"];

            })

            _Html = "";

            //当前登录人员的编号.
            var userNo = webUser.No;
            var todoEmpsName = "";
            htmlbox = '';
            var realIndex = startIndex;
            for (var i = 0; i < flowData.length; i++) {
                var en = flowData[i];

                if (en.FID != 0)
                    continue;

                ++realIndex;

                var fk_flow = en.FK_Flow,
                    fk_node = en.FK_Node,
                    workid = en.WorkID,
                    fid = en.FID,
                    isRead = en.IsRead,
                    paras = en.AtPara;

                if (paras == null || paras == "") {
                    paras = "";
                }
                else {
                    if (paras.indexOf("IsCC=1") > -1) {
                        paras = "IsCC=1";
                    } else {
                        paras = "";
                    }
                }

                //审批人
                var todoEmps = en.TodoEmps;
                var emp = "";
                if (todoEmps != null && todoEmps != undefined) {

                    var todoEmp = todoEmps.split(";");
                    for (j = 0; j < todoEmp.length; j++) {
                        if (todoEmp[j] == '' || todoEmp[j] == null || todoEmp[j] == undefined)
                            continue;
                        if (todoEmp[j].indexOf(',') != -1) {
                            var aa = todoEmp[j].split(",")[1] + "、";
                            emp += aa;

                        } else {
                            emp += todoEmp[j] + "、";
                        }

                    }
                    emp = emp.substring(0, emp.lastIndexOf("、"));
                }

                //是否可以执行当前工作?
                var isCanDo = false;
                if (en.TodoEmps != null) {
                    if (en.TodoEmps.indexOf(webUser.No) != -1)
                        isCanDo = true;
                }

                //获得icon.
                var icon = GenerICON(isCanDo, en.WFState);

                // 获得颜色.
                var color = GenerColor(en.WFState, isCanDo);

                htmlbox += "<tr >";
                htmlbox += "<td class=Idx>" + realIndex + "</td>";

                htmlbox += "<td><a href=\"javascript:OpenIt('" + en.WFState + "','" + en.WorkID + "','" + en.FK_Flow + "','" + en.FK_Node + "','" + en.TodoEmps + "','" + userNo + "')\">" + en.Title + "</td>";

                htmlbox += "<td><font color='" + color + "'>" + en.StarterName + "</font></td>";

                htmlbox += "<td><font color='" + color + "'>" + en.RDT.substring(5) + "</font></td>";

                htmlbox += "<td><font color='" + color + "'>" + en.NodeName + "</font></td>";

                htmlbox += "<td ><font color='" + color + "'>" + emp + "</font></td>";

                if (en.SDTOfNode == null)
                    htmlbox += "<td><font color='" + color + "'>无</font></td>";
                else
                    htmlbox += "<td><font color='" + color + "'>" + en.SDTOfNode.substring(5) + "</font></td>";

                htmlbox += "<td><font color='" + color + "'>" + GetWFState(en.WFState, isCanDo) + "</font></td>";

                htmlbox += "<td><font color='" + color + "'>" + GenerOper(en.WorkID, en.WFState, en.FK_Flow, en.FK_Node, en.FID, isCanDo) + "</font></td>";

                htmlbox += "</tr>";

            }
            $("#Table1").html(htmlbox);
            $("#List").append(_Html);
            $("#Msg").html(""); 
        }


        //分页功能
        function Paginator(pageCount, currentPage) {
            var pageCount = pageCount; //取到pageCount的值(把返回数据转成object类型)
            var options = {
                bootstrapMajorVersion: 3, //版本
                currentPage: currentPage, //当前页数
                totalPages: pageCount, //总页数
                shouldShowPage: true, //是否显示该按钮
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                }, //点击事件，用于通过Ajax来刷新整个list列表
                onPageClicked: function (event, originalEvent, type, page) {
                    pageIdx = page;
                    keyWord = $("#TB_Key").val();
                    IsSearchClick = false;//重置是否点击查询
                    IsPageClick = true;//点击了页码

                    InitPage(keyWord);
                    InitData();
                    mouseShow();
                    $('#page_info').html("").append("<li class='disabled controls'>当前第" + pageIdx + "页，总共" + pageCount +
                            "页,总共" + total + "条记录。</li>");
                }
            };
            $('#page_nav').bootstrapPaginator(options);
            $('#page_info').html("").append("<li class='disabled controls'>当前第" + pageIdx + "页，总共" + pageCount +
                            "页,总共" + total + "条记录。</li>");

        }

        function GenerOper(workID, wfState,flowNo,nodeID,fid,isCanDo) {

            if (wfState == 3)
                return "";

            if (wfState == 2 && isCanDo == true)
                return "";

            if (wfState == 3)
                return "<a href=''>轨迹</a>";

            if (wfState == 2)
                return "<a href=\"javascript:UnSend('"+flowNo+"','"+nodeID+"','"+workID+"','"+fid+"');\" >撤销</a>";


            var url = "WFRpt.htm?WorkID=" + workID + "&FK_Flow=" + flowNo+"&FK_Node="+nodeID;

            return "<a href=\"javascript:WinOpen('"+url+"');\" >轨迹</a>";
        }

        function UnSend(flowNo, nodeID, workid, fid) {

            if (confirm("您确定要撤销吗？") == false)
                return;

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt_OneWork");
            handler.AddPara("FK_Node", nodeID);
            handler.AddPara("FK_Flow", flowNo);
            handler.AddPara("WorkID", workid);
            handler.AddPara("FID", fid);
            var data = handler.DoMethodReturnString("OP_UnSend");
            alert(data);
            window.location.href = window.location.href;
        }
        function GenerColor(wfState, isCanDo) {

            if (isCanDo == true && wfState != 3)
                return "red";

            if (wfState == 5) {
                return "yellow";
            }

            if (wfState == 3) {
                return "green";
            }

            if (wfState == 2)
                return "";

            return "";
        }

        function GetWFState(wfState, isCanDo) {

            if (isCanDo == true && wfState!=3)
                return "待办";

            if (wfState == 5) {
                return "退回";
            }

            if (wfState == 3) {
                return "已完成";
            }

            if (wfState == 2)
                return "运行中";

            return "其他";
        }
        function GenerICON(isCanDo, wfState) {

            if (wfState == 3)
                icon = "./Img/WFState/Complete.png";  //已经完成.
            else if (wfState == 2)
                icon = "./Img/WFState/Runing.png"; //运行中. 
            else if (wfState == 5)
                icon = "./Img/WFState/ReturnSta.png"; //退回.
            else
                icon = "./Img/WFState/Etc.png"; //其他.

            if (isCanDo == true && wfState != 3)
                icon = "./Img/WFState/Todo.png"; //其他.

            return icon;
        }

        function OpenIt(wfState, workid, flowNo, nodeID, emps, userNo) {

            var url = "";

            if (wfState != 3 && emps.indexOf(userNo) >= 0) {
                url = "MyFlow.htm?WorkID=" + workid + "&FK_Flow=" + flowNo + "&FK_Node=" + nodeID;
                var self = window.open(url);
                var loop = setInterval(function () {
                    if (self.closed) {
                        clearInterval(loop);
                        InitPage(); //初始化查询列表、
                        InitData(); //初始化数据
                        Paginator(pageCount, pageIdx); //分页
                        InitHomeCount();
                    }
                }, 1);   
                return;

            } else {
                url = "WFRpt.htm?WorkID=" + workid + "&FK_Flow=" + flowNo + "&FK_Node=" + nodeID;
            }
           
            layer.open({
				  skin: 'layer-class',	
				  type: 2, 
				  title: '我的流程', 
				  area:['96%','90%'],
				  content: url
				});
        }

        function TSpan(tspan) {

            var flowNo = GetQueryString("FK_Flow");
            if (flowNo == null) {
                if (tspan == '')
                    window.location.href = '?1=1';
                else
                    window.location.href = '?TSpan=' + tspan;
            }
            else {
                if (tspan == '')
                    window.location.href = '?FK_Flow=' + flowNo;
                else
                    window.location.href = '?FK_Flow=' + flowNo + '&TSpan=' + tspan;
            }
        }
        

        function Flows(flowNo) {
            var tspan = GetQueryString("TSpan");

            if (tspan == null) {
                if (flowNo == "")
                    window.location.href = '?1=1';
                else
                    window.location.href = '?FK_Flow=' + flowNo;
            }
            else {

                if (flowNo == "")
                    window.location.href = '?TSpan=' + GetQueryString("TSpan");
                else
                    window.location.href = '?FK_Flow=' + flowNo + '&TSpan=' + GetQueryString("TSpan");
            }
        }
        //跳转url
        function ToUrl(pageID) {
            var url = pageID + ".htm?m=" + Math.random();
            window.location.href = url;
        }
        //关键字查询
        function SearchKey() {
            IsSearchClick = true;//点击了查询
			IsPageClick = false;//重置点击页面
            keyWord = $("#TB_Key").val();
            InitPage(keyWord);
            InitData();
            Paginator(pageCount, pageIdx);
        }
        //鼠标悬浮显示
        function mouseShow() {
             $("td").on("mouseover",function() {
                if (this.offsetWidth < this.scrollWidth) {
                    var that = this;
                    var text = $(this).text();
                   layer.tips("<span style='color:#000'>"+text+"</span>", that,{
                        tips:[1,'#FFF'],
                        time: 0
                   });
                }
            });
            $("td").on("mouseout",function(){
            layer.closeAll("tips");//关闭所有tips，避免和iframe冲突
            });
        }
    </script>        
        
</body>
</html>
